using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace Kdg.Windows.Forms
{
    public partial class ProgressBar : System.Windows.Forms.ProgressBar
    {
        Color colorStart = Color.LightBlue;
        Color colorEnd = Color.LightGreen;

        public ProgressBar()
        {
            InitializeComponent();

            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
        }

        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            base.OnPaintBackground(pevent);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Rectangle rect = new Rectangle(
                this.ClientRectangle.X,
                this.ClientRectangle.Y,
                (int)((double)this.ClientRectangle.Width * ((double)this.Value / 100.0)),
                this.ClientRectangle.Height);
            if (rect.Width != 0 && rect.Height != 0)
            {
                Brush br = new LinearGradientBrush(rect, colorStart, colorEnd, LinearGradientMode.Horizontal);
                e.Graphics.FillRectangle(br, rect);
            }

            e.Graphics.DrawRectangle(Pens.DarkGray, 
                this.ClientRectangle.X,
                this.ClientRectangle.Y,
                this.ClientRectangle.Width-1,
                this.ClientRectangle.Height-1);
            string val = Value.ToString() + "%";
            SizeF szf = e.Graphics.MeasureString(val, this.Font);

            e.Graphics.DrawString(
                val,
                this.Font,
                new SolidBrush(this.ForeColor),
                (this.ClientRectangle.Width - szf.Width) / 2.0f,
                (this.ClientRectangle.Height - szf.Height) / 2.0f);
        }

        [Category("Appearance")]
        public Color ColorStart
        {
            get { return colorStart; }
            set { colorStart = value; }
        }

        [Category("Appearance")]
        public Color ColorEnd
        {
            get { return colorEnd; }
            set { colorEnd = value; }
        }
        [Browsable(true)]
        override public Font Font
        {
            get { return base.Font; }
            set { base.Font = value; }
        }

    }
}
